package com.example.neusoft.yuejian.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian.Base.BaseActivity;
import com.example.neusoft.yuejian.Base.BaseListener;
import com.example.neusoft.yuejian.Base.BaseModel;
import com.example.neusoft.yuejian.Bean.ActBean;
import com.example.neusoft.yuejian.Bean.ActenrollBean;
import com.example.neusoft.yuejian.Bean.MatchBean;
import com.example.neusoft.yuejian.Bean.MatchDetailBean;
import com.example.neusoft.yuejian.Bean.MyBean;
import com.example.neusoft.yuejian.R;

import retrofit2.Call;

public class MatchEnrollActivity extends BaseActivity implements View.OnClickListener{
        private MatchDetailBean match;
        private MyBean mine;
        private TextView bsmc,yhmz,lxfs,bsjg,bssj,bsdz;
        private Button qrbm;
        private Context context;
        private SharedPreferences sp ;
        private int id,uid;
        private ImageView fh;


        @Override
        public int getLayoutFile() {
            return R.layout.match_enroll;
        }

        @Override
        public void initView() {
            bsdz=(TextView)findViewById(R.id.bsdz);
            yhmz=(TextView)findViewById(R.id.yhmz);
            bsmc=(TextView)findViewById(R.id.bsmc);
            lxfs=(TextView)findViewById(R.id.lxfs);
            bsjg=(TextView)findViewById(R.id.bsjg);
            bssj=(TextView)findViewById(R.id.bssj);
            qrbm=(Button) findViewById(R.id.qrbm);
            fh=(ImageView)findViewById(R.id.fh);

        }

        @Override
        public void initEvent() {
            qrbm.setOnClickListener(this);
            fh.setOnClickListener(this);
        }


        @Override
        public void initData() {
            match=(MatchDetailBean) getIntent().getSerializableExtra("mid");
            context= com.example.neusoft.yuejian.Activity.MatchEnrollActivity.this;
            sp=context.getSharedPreferences("User", context.MODE_PRIVATE);
            uid= sp.getInt("id",0);
            bsdz.setText(match.getMaddress());
            bsjg.setText(match.getMprice());
            bsmc.setText(match.getMname());
            bssj.setText(match.getMstarttime());
            id=match.getMid();
            getMine(uid);

        }
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.qrbm:
                    getenroll(id,uid);
                    break;
                case R.id.fh:
                   finish();
                    break;
            }
        }
        public void getenroll(int id,int uid){
            BaseModel<ActenrollBean> model=new BaseModel<>();
            Call<ActenrollBean> call=model.service.getmatchenroll(id,uid);
            model.callEnqueue(call,listener);
        }
        BaseListener<ActenrollBean> listener=new BaseListener<ActenrollBean>() {
            @Override
            public void onResponse(ActenrollBean actenrollbean) {
                if(actenrollbean.getStatus()==1){
                    showToast(actenrollbean.getMessage());

                }else{
                    showToast(actenrollbean.getMessage());

                }
            }

            @Override
            public void onFail(String message) {
                showToast("123");
            }
        };
        private void getMine(int uid ){
            BaseModel<MyBean> model = new BaseModel<>();
            Call<MyBean> call = model.service.getMine(uid);
            model.callEnqueue(call, list);
        }
        BaseListener<MyBean> list=new BaseListener<MyBean>() {
            @Override
            public void onResponse(MyBean myBean) {
                mine=myBean;
                yhmz.setText(myBean.getUname());
            }

            @Override
            public void onFail(String msg) {

            }
        };
}
